<?php
$ta="2009/2010";
$matkul= array("MES 251","MPK 101","MPK 102","TEK 103","TEK 109","TEK 115","TEK 201","TEK 101","TEL 101","TEL 103","TEL 201","TEL 203","TEL 205","TEL 207","TEL 209","TEL 212","TEL 301","TEL 303","TEL 305","TEL 307","TEL 309","TEL 311","TEL 313","TEL 315","TEL 401","TEL 403","TEL 405","TEL 413","TEL 415","TEL 417","TEL 419","TEL 421","TEL 423","TEL 425","TEL 439");
$jmlah_matkul=count($matkul);

foreach($matkul as $key => $nilai){
$no_matkul[$key]=$key;
$nama_matkul[$key] = $nilai;
}unset($key);unset($nilai);
?>

<?php require_once('Connections/dodol.php'); 
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
	{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;}
}


for($a=0;$a<$jmlah_matkul;$a++)
{
$matkul1=$nama_matkul[$a];
mysql_select_db($database_dodol, $dodol);
$query_db = sprintf("SELECT no, nim FROM matkul_db WHERE kode_matkul = %s AND ta = %s", GetSQLValueString($matkul1, "text"),GetSQLValueString($ta, "text"));
$matkul_db = mysql_query($query_db, $dodol) or die(mysql_error());		//query
$row_db = mysql_fetch_assoc($matkul_db);								//dapetin barisnya
$totalRows_db = mysql_num_rows($matkul_db);								//total barisnya

echo $matkul1."<br/>";$i=0;
do {$i++;
$no[$i]=$row_db['no'];$nim[$i]=$row_db['nim'];
//echo $no[$i]." ".$nim[$i]."<br/>\n";
} 
while ($row_db = mysql_fetch_assoc($matkul_db));
echo $atas=$no[1]." - ".$bawah=$no[$totalRows_db];
echo $ab=(($bawah-$atas)+1)."<br/>";

/*SELECT * FROM `matkul_db` where no<"347" || no >"410"*/
mysql_select_db($database_dodol, $dodol);
$query_db2 = sprintf("SELECT no, nim FROM matkul_db where no < %s || no > %s",GetSQLValueString($atas, "text"),GetSQLValueString($bawah, "text"));
$matkul_db2 = mysql_query($query_db2, $dodol) or die(mysql_error());
$row_db2 = mysql_fetch_assoc($matkul_db2);
$totalRows_db2 = mysql_num_rows($matkul_db2);
$i=0;
do{$i++;
$total[$i] =$row_db2['nim'];
}
while ($row_db2 = mysql_fetch_assoc($matkul_db2));
echo $totalRows_db2;
echo "<br/>\n";
}
?>